package com.yhn.bubblevideo.video.controller;

import com.yhn.bubblevideo.common.model.BaseResponse;
import com.yhn.bubblevideo.common.model.ResultUtils;
import com.yhn.bubblevideo.model.dto.req.video.VideoPostRequestDTO;
import com.yhn.bubblevideo.video.service.VideoService;
import com.yhn.bubblevideo.video.service.VideoUploadService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2024/12/20 15:43
 */
@RestController
public class VideoUploadController {
    @Resource
    private VideoService videoService;
    @Resource
    private VideoUploadService videoUploadService;

    @PostMapping("/pre-upload")
    public BaseResponse<String> preUpload(@RequestParam("fileName") String fileName, @RequestParam("chunkSize") Integer chunkSize) {
        return ResultUtils.success(videoUploadService.preUpload(fileName, chunkSize));
    }

    @PostMapping("/upload/video")
    public BaseResponse<String> uploadVideo(MultipartFile file, Integer chunkIndex, String uploadId) {
        return ResultUtils.success(videoUploadService.uploadVideo(file, chunkIndex, uploadId));
    }

    @PostMapping("/delete/video")
    public BaseResponse<Boolean> deleteUploadVideo(String uploadId) {
        return ResultUtils.success(videoUploadService.deleteUploadVideo(uploadId));
    }

    @PostMapping("/upload/image")
    public BaseResponse<String> uploadImage(MultipartFile file) {
        return ResultUtils.success(videoUploadService.uploadImage(file));
    }

    @PostMapping("/upload/finish")
    public BaseResponse<String> transferVideoFile(String uploadId) {
        return ResultUtils.success(videoUploadService.completeMultipartUpload(uploadId));
    }

    @PostMapping("/post/video")
    public BaseResponse<Long> postVideo(@RequestBody VideoPostRequestDTO requestParam) {
        return ResultUtils.success(videoService.postVideo(requestParam));
    }


}
